package com.sunday.volunteer.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.sunday.member.base.BaseActivity;
import com.sunday.volunteer.R;
import com.sunday.volunteer.utils.BaseUtil;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by Pual's PC on 2016/10/18.
 */
public class WebViewActivity extends BaseActivity {
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.web_view)
    WebView webView;

    private String url;
    private String title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);
        ButterKnife.bind(this);


        url = getIntent().getStringExtra(BaseUtil.URL);
        title = getIntent().getStringExtra(BaseUtil.TITLE);
        if(TextUtils.isEmpty(url)){
            url ="http://baike.baidu.com/link?url=TtMa4-82XHifGl2RMqv_rQgnyI0WvhZvrOtBAtCp_hOkkfCaYjSDU1AnroNw1dRpvkHx73vzWcY5ZlqTeGArIa";
        }
        Log.d("url" , url);
        showLoadingDialog(0);
        if(!TextUtils.isEmpty(title)){
            titleText.setText(title);
        }
        WebSettings webSettings =   webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setSupportZoom(false);
        webView.setWebChromeClient(new WebChromeClient());
        webView.setWebViewClient(new WebViewClient(){
            // 这个方法在用户试图点开页面上的某个链接时被调用
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if(!TextUtils.isEmpty(url)) {
                    view.loadUrl(url);
                }else {
                    dissMissDialog();
                }
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                dissMissDialog();
            }
        });
        webView.loadUrl(url);

    }


}
